import ElectronStore from 'electron-store'
import { app, ipcMain } from 'electron'
const Store = (ElectronStore as any).default || ElectronStore

const store = new Store({
  name: 'base',
  cwd: app.getPath('userData')
})

export default function registerBaseStoreIpc(): void {
  ipcMain.handle('base-get-folder', (_, type?: 'Note' | 'Mind') => {
    const key = type === 'Mind' ? 'mindFolderPath' : 'noteFolderPath'
    return store.get(key, '')
  })
  ipcMain.handle('base-set-folder', (_, type: 'Note' | 'Mind', folderPath: string) => {
    const key = type === 'Mind' ? 'mindFolderPath' : 'noteFolderPath'
    store.set(key, folderPath || '')
    return folderPath || ''
  })
  // 暗夜模式
  ipcMain.handle('base-get-theme', () => store.get('theme', 'light'))
  ipcMain.handle('base-set-theme', (_, theme: 'light' | 'dark') => {
    store.set('theme', theme || 'light')
    return theme || 'light'
  })
}
